package com.yonyou.pmclouds.safetyrectification.util;

import com.yonyou.pmclouds.safetyrectification.entity.SafetyRectiBillStatusConst;
import com.yonyou.pmclouds.safetyrectification.entity.SafetyRectificationVO;
import com.yonyou.pmclouds.safetyrectification.entity.SeverityLevelConst;

import java.util.Calendar;

/**
 * 安全整改工具类
 *
 * @author th
 * @date 2019/11/5 13:54
 */
public class SafetyRectifyUtil {
    /**
     * 翻译严重级别
     *
     * @param vo
     * @return
     */
    public static String transSeverityLevel(SafetyRectificationVO vo) {
        String result = "一般问题";
        switch (vo.getSeverityLevel()) {
            case SeverityLevelConst.GENERAL_PROBLEM:
                result = "一般问题";
                break;
            case SeverityLevelConst.SERIOUS_PROBLEM:
                result = "严重问题";
                break;
            case SeverityLevelConst.FATAL_PROBLEM:
                result = "紧急问题";
                break;
            case SeverityLevelConst.GENERAL_DANGER:
                result = "一般隐患";
                break;
            case SeverityLevelConst.SERIOUS_DANGER:
                result = "严重隐患";
                break;
            case SeverityLevelConst.FATAL_DANGER:
                result = "重大隐患";
                break;
            default:
                break;
        }

        return result;
    }

    /**
     * 翻译单据状态
     *
     * @param vo
     * @return
     */
    public static String transBillStatus(SafetyRectificationVO vo) {
        String result = "待整改";
        if (SafetyRectiBillStatusConst.STATUS_RECTIFING.equals(vo.getBillStatus())) {
            result = "待整改";
        } else if (SafetyRectiBillStatusConst.STATUS_ACCEPTING.equals(vo.getBillStatus())) {
            result = "待验收";
        } else if (SafetyRectiBillStatusConst.STATUS_END.equals(vo.getBillStatus())) {
            result = "已关闭";
        }

        return result;
    }

    /**
     * 判断是否超期
     *
     * @param vo
     * @return
     */
    public static boolean checkOverTime(SafetyRectificationVO vo) {
        if (!SafetyRectiBillStatusConst.STATUS_RECTIFING.equals(vo.getBillStatus()))
            return false;

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);

        if (cal.getTime().compareTo(vo.getDeadline()) > 0)
            return true;

        return false;
    }
}
